package cn.org.xuanzp.accept.provider;

import cn.org.xuanzp.common.command.Command;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname AbstractAcceptProvider
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/9/22 0:32
 * @Created by xuanzp
 */
public abstract class AbstractAcceptProvider implements AcceptProvider {
    private Map<Class,AcceptProvider> providers = new HashMap<>();



    @Override
    public void accept(Command command) {
        providers.forEach((k,v)->{
            if(v.support(command)){
                v.accept(command);
            }
        });
    }

    /***
     * 增加
     * @param provider
     */
    public void addProvider(AcceptProvider provider){
        providers.put(provider.getClass(),provider);
    }


    /***
     * 减少
     * @param provider
     */
    public void removeProvider(AcceptProvider provider){
        providers.remove(provider.getClass());
    }

    /***
     * 判断是否支持
     * @param o
     * @return
     */
    @Override
    public Boolean support(Object o) {
        return Boolean.TRUE;
    }
}
